import 'package:flutter/material.dart';
import 'package:top_foundation/component/tabbar/index.dart';
import 'package:top_foundation/utils/util.dart';
import 'package:top_foundation_example/fade_tabbar/index.dart';

import 'index.dart';

class SplashPage extends StatelessWidget {
  SplashPage({Key? key}) : super(key: key);
  final controller = Get.put(SplashController());
  final state = Get.find<SplashController>().state;

  // 主视图
  Widget _buildView() {
    return Column(
      children: [
        TPTabBar(
          controller: state.tbCtrl,
          // isScrollable: true,
        ),
        Expanded(
          child: TPTabBarView(
            controller: state.tbCtrl,
            pageBuilder: (context, index) {
              return [
                Container(
                  color: Colors.amber,
                ),
                Container(
                  color: Colors.brown,
                ),
                Container(
                  color: Colors.pinkAccent,
                ),
                Container(
                  color: Colors.blueAccent,
                ),
                Container(
                  color: Colors.cyanAccent,
                ),
                Container(
                  color: Colors.pinkAccent,
                ),
                Container(
                  color: Colors.blueAccent,
                ),
                Container(
                  color: Colors.cyanAccent,
                ),
                Container(
                  color: Colors.pinkAccent,
                ),
              ][index];
            },
          ),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SplashController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(
            title: const Text("splash"),
            actions: [
              TextButton(
                  onPressed: () {
                    Get.to(
                      () => const FadeTabbarPage(),
                      binding: FadeTabbarBinding(),
                    );
                  },
                  child: const Text(
                    'tabbar',
                    style: TextStyle(color: Colors.white),
                  ))
            ],
          ),
          body: SafeArea(
            child: Container(
                padding: EdgeInsets.symmetric(horizontal: 30.r),
                child: _buildView()),
          ),
        );
      },
    );
  }
}
